import './styles/index.scss'
import { createApp } from 'vue'
import App from './App.vue'
import router, { setupRouter } from '@/router/index' // 路由
import { setupStore } from '@/store/index'
import ipcBridge from '@/utils/ipc-bridge'

// element-plus相关
import 'element-plus/dist/index.css' // element css
import 'element-plus/theme-chalk/dark/css-vars.css' // 暗黑模式
import * as ElementPlusIconsVue from '@element-plus/icons-vue' // element图标
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn' // element 中文

// 注册全局自定义指令

// 挂载全局方法
async function bootstrap() {
  // 创建vue实例
  const app = createApp(App)

  // 挂载状态管理
  setupStore(app)

  // 挂载路由
  setupRouter(app)
  await router.isReady() // 等待路由准备就绪, 路由准备就绪后挂载 APP 实例

  // 挂载ipc通信
  app.use(ipcBridge)

  // 注册element图标
  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }

  // element 国际化
  app.use(ElementPlus, { locale: zhCn })

  // 挂载应用
  app.mount('#app', true)
}

void bootstrap()
